import { NMTopoBaseCommand } from '@app-cad/environments/nextmesh/types/command';

import i18n from '@app-cad/common/utils/i18next';
import { CommandDialog } from '@amcax/base';
import { MsComponent } from '../cmd-common/component';
import { getNormalsOrIds, Picktip, SetPick } from '../cmd-common/tools';
import { RJSFSchema } from '@rjsf/utils';
import { PickInputRJSFFormat } from '@app-base/common/components/command-form/constants';
const schema: RJSFSchema = {
  type: 'object',
  properties: {
    source: {
      type: 'array',
      items: {
        type: 'string',
        enum: [],
      },
      format: PickInputRJSFFormat.MultiPickALL,
      uniqueItems: true,
    },
    relyOn: SetPick('PickPlane'),
  },
};
const extraUiSchema = {
  source: Picktip(true, '点/线/面'),
  relyOn: Picktip(false, '镜像面'),
};
const lineParam = (formData) => {
  const sourceIds = getNormalsOrIds(formData.source, 'id').map((it) => it.id);
  const targetId = getNormalsOrIds([formData.relyOn], 'id').map((it) => it.id);
  if (sourceIds.length > 0 && targetId.length > 0) {
    const param = {
      target: targetId,
      source: sourceIds,
      mode: 'mirror',
    };
    return param;
  }
  return null;
};
export function Command({ onClose, title }) {
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <MsComponent
        onClose={onClose}
        formatParam={lineParam}
        formParams={{
          schemaParams: schema,
          extraUiSchema: extraUiSchema,
        }}
        wsApi='transform'
      />
    </CommandDialog>
  );
}

export const cmdTopoMirror: NMTopoBaseCommand = {
  id: 'cmdTopoMirror',
  label: 'command.topo.mirror',
  icon: 'commands/feature/mirror',
  create: function (label: string, onClose: () => void) {
    return (
      <Command
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
